package com.bbcare.followup.plat.controller.fd;

import com.bbcare.comm.ResultModel;
import com.bbcare.comm.ToolUtil;
import com.bbcare.comm.ToolUtils;
import com.bbcare.followup.plat.entity.DumpPlanUpload;
import com.bbcare.followup.plat.service.IDumpMessageRecordService;
import com.bbcare.followup.plat.service.IDumpPlanUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 复旦儿科母乳上传登记Controller
 *
 * @author gxl
 * @date 2020-11-03
 */
@RestController
@RequestMapping("/service/DumpPlanUpload")
public class DumpPlanUploadController {
    @Autowired
    private IDumpPlanUploadService dumpPlanUploadService;
    @Autowired
    private IDumpMessageRecordService dumpMessageRecordService;

    /**
     * 查询复旦儿科母乳上传登记列表
     */

    @PostMapping("/list")
    public ResultModel<Map<String, Object>> list(@RequestBody Map params) {


        Map map = new HashMap();
        Integer currentPage = Integer.parseInt(params.get("currentPage").toString());
        Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
        params.put("start",pageSize*(currentPage-1));
        params.put("end",pageSize*currentPage);
        List<DumpPlanUpload> list = dumpPlanUploadService.selectDumpPlanUploadList(params);
        Integer total = dumpPlanUploadService.selectCountDumpPlanUploadRecord(params);
        map.put("data", list);
        map.put("count",total);
        return new ResultModel(map);
    }



    /**
     * 获取复旦儿科母乳上传登记详细信息
     */

    @PostMapping(value = "/getInfo")
    public ResultModel<Map<String, Object>> getInfo(@RequestBody Map param)  {
        return  new ResultModel(dumpPlanUploadService.selectDumpPlanUploadById(param.get("id").toString()));
    }

    /**
     * 获取复旦儿科母乳上传记录未读人员
     */

    @PostMapping(value = "/getUnreadPatientId")
    public ResultModel<Map<String, Object>> getUnreadPatientId(@RequestBody Map param)  {
        return  new ResultModel(dumpMessageRecordService.getUnreadPatientId(param.get("id").toString()));
    }
    /**
     * 新增复旦儿科母乳上传登记
     */

    @PostMapping(value = "/add")
    ResultModel<Map<String, Object>> add(@RequestBody DumpPlanUpload dumpPlanUpload, HttpServletRequest request){
        Map<String, Object> sessionMap = ToolUtils.getSessionInfo(request);
        dumpPlanUpload.setAuth( sessionMap.get("authorName").toString());
        dumpPlanUploadService.insertDumpPlanUpload(dumpPlanUpload);
        dumpMessageRecordService.sendWxMessage(dumpPlanUpload);
        return new ResultModel("添加成功");
    }

    /**
     * 修改复旦儿科母乳上传登记
     */

    @PostMapping(value = "/update")
    public ResultModel<Map<String, Object>> edit(@RequestBody DumpPlanUpload dumpPlanUpload) {
        dumpPlanUploadService.updateDumpPlanUpload(dumpPlanUpload);
        return new ResultModel("修改成功");
    }

    /**
     * 删除复旦儿科母乳上传登记
     */

    @PostMapping("/delete")
    public ResultModel<Map<String, Object>> remove(@RequestBody String[] ids) {
        dumpPlanUploadService.deleteDumpPlanUploadByIds(ids);
        return new ResultModel("删除成功");
    }
}
